package ${packageName}.service.${moduleName}.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${packageName}.dao.entity.${moduleName}.${entity_name};
import ${packageName}.dao.mapper.${moduleName}.${entity_name}Mapper;
import ${packageName}.service.${moduleName}.${entity_name}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ${entity_name}ServiceImpl implements ${entity_name}Service{

    @Autowired
    private ${entity_name}Mapper ${entity_name_low}Mapper;

    @Override
    public void save(${entity_name} ${entity_name_low}) {
        ${entity_name_low}.setCreateDate(new Date());
        ${entity_name_low}Mapper.insertUseGeneratedKeys(${entity_name_low});
    }

    @Override
    public void edit(${entity_name} ${entity_name_low}) {
        ${entity_name_low}.setUpdateDate(new Date());
        ${entity_name_low}Mapper.updateByPrimaryKeySelective(${entity_name_low});
    }

    @Override
    public void delete(Integer[] ids) {
        for (Integer id : ids) {
            ${entity_name_low}Mapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public ${entity_name} find${entity_name}(Integer id) {
        return  ${entity_name_low}Mapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<${entity_name}> page(Page<${entity_name}> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<${entity_name}>  datas =  ${entity_name_low}Mapper.selectAll();
        PageInfo<${entity_name}> pageInfo = new PageInfo<>(datas);
        return pageInfo;
    }

}